package com.scau.clothes.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtil implements ApplicationContextAware {
    private static ApplicationContext appCtx;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appCtx=applicationContext;
    }
    public static Object getBean(String name) {
        return appCtx.getBean(name);
    }
    public static <T> T getBean(Class<T> clazz){
        return appCtx.getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> requiredType) {
        return appCtx.getBean(name, requiredType);
    }

    public static boolean containsBean(String name) {
        return appCtx.containsBean(name);
    }

    public static boolean isSingleton(String name) {
        return appCtx.isSingleton(name);
    }

    public static Class<?> getType(String name) {
        return appCtx.getType(name);
    }
}
